/**
 * @class   wosh::services::ButlerBundle
 * @brief   
 *
 *
 *

the automation system should not limit you in the way you where used to to things in the house, it should only add comfort to it!
 
 * => EVENTS from SecurityBus, Building
 *
 * ---------------------------------------------------------------
 *  - report door bell signal as Notification when home is empty
 *    - retrieve door bells
 *    - eval EVENT _BuildingObject_EVENT_StateChanged in BusBuilding
 * ---------------------------------------------------------------
 *  - when leaving home (no users in):
 *    - pause music?
 *    - turn off home lights
 *    - turn on garden lights?
 *
 * ---------------------------------------------------------------
 *  - when entering home  (no users in):
 *    - restore music? [eval timeOfDay?]
 *    - 
 *    - 
 *
 *
 *
 * ---------------------------------------------------------------
 * ---------------------------------------------------------------
 * ---------------------------------------------------------------
 * Butler assists inhabitans and take care of home
 *
 *  - turn on/off lights on movement-detection
 *
 *  - turn off garden lights when day, when home is empty at night
 *
 *  - turn off lights, music when leaving home
 *

 *
 *
 * @ingroup Services
 ****************************************************************************
 * @version $Id: ButlerBundle.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Bundles_Services_Butler_H__
 #define __WOSH_Bundles_Services_Butler_H__

 #include <core/BundleGeneric.h>
 #include <core/Thread.h>

 #include <core/Communicator.h>
 #include <interfaces/Service.h>
 #include <interfaces/services/Butler.h>
 #include <interfaces/services/CommunicatorService.h>

 #include "IButlerListener.h"

class ButlerBot;

namespace wosh {
 namespace services {

 #define _Butler_VERSION			0.02


class ButlerBundle :	public BundleGeneric,
						public virtual wosh::interfaces::services::CommunicatorService,
						public virtual wosh::interfaces::services::Butler,
						public virtual IButlerListener
 {
	WOSH_BUNDLE(wosh::services::ButlerBundle)
	WOSH_BUNDLE_INTERFACE("wosh::interfaces::services::Butler")
	WOSH_BUNDLE_SINGLETON(1,0)


	public:
		ButlerBundle();

		virtual ~ButlerBundle();


	public:
		WRESULT bundleStart();
		WRESULT bundleStop();

		void busMessage( const Message& message, const Bus* source );

		bool updatingProperty( bool& do_update, const Data& value_proposed, Property& property_current, const PropertiesProvider* source );

//@}
/** @name Butler Interface
 * @{
 ******************************************************************************/
	public:

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:

//@}
/** @name CommunicatorService Interface
 * @{
 ******************************************************************************/
	public:
		bool isUserReachable( const string& wosh_username );
		WRESULT sendMessageToUser( const string& wosh_username, const string& message );
		WRESULT sendMessageTo( const string& custom_username, const string& message );
		WRESULT notify( const Notification* notification );

//@}
/** @name CommunicationManager Interface for Communication callbacks
 * @{
 ******************************************************************************/
	public:
		void updateObject( MessageContent* content, const string& uri, ButlerImpl* );

//@}
/** @name Internal methods
 * @{
 ******************************************************************************/
	protected:
		WRESULT updateDoorBells();

//@}
	private:
		Response* mmDoSendMessageToUser( const Message* requestMessage );
		Response* mmDoListDoorBells( const Request* request );

	protected:
		BusConnector BusBuilding;
		BusConnector BusSecurity;

		ButlerImpl* butlerWorker;
		ButlerBot* butlerBot;


}; // class def

 }; // namespace services
}; // namespace wosh

#endif //__WOSH_Bundles_Services_Butler_H__
